package cn.study.controller;

import cn.study.entity.*;
import cn.study.service.StudyBannerService;
import cn.study.service.StudyCommodityService;
import cn.study.service.StudyCourseService;
import cn.study.service.StudyNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * @date 2020/7/11 -8:20
 */
@Controller
@RequestMapping("/study")
public class IndexController {

    @Resource
    StudyNoticeService studyNoticeService;
    @Resource
    StudyCourseService studyCourseService;
    @Resource
    StudyBannerService studyBannerService;
    @Resource
    StudyCommodityService studyCommodityService;
    @GetMapping("/index")
    public String index(Model model,@RequestParam(value = "id", required = false ) Integer id) {
        List<StudyNotice> list = studyNoticeService.getlist();
        List<StudyCourse> videolist = studyCourseService.getByDepByRoleList(id);
        List<StudyBanner> bannerlist = studyBannerService.getBanner(id);
        List<StudyCourse> xlist = studyCourseService.getCourseTypeList(id);
        List<StudyCourse> blist = studyCourseService.getCourseBITypeList(id);
        QueryWrapper<StudyCommodity> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time")
                .last("limit 0,4");
        List<StudyCommodity> commodities=studyCommodityService.list(queryWrapper);
        model.addAttribute("list", list);
        model.addAttribute("videolist",videolist);
        model.addAttribute("bannerlist",bannerlist);
        model.addAttribute("xlist",xlist);
        model.addAttribute("blist",blist);
        model.addAttribute("commodities",commodities);
        return "index";
    }
}
